package com.jsyl.lwbk.web.controller.business;

import com.jsyl.lwbk.business.domain.CourseChildProject;
import com.jsyl.lwbk.business.domain.education.ChildCourse;
import com.jsyl.lwbk.business.dto.ChildCourseDTO;
import com.jsyl.lwbk.business.dto.ChildInfoDTO;
import com.jsyl.lwbk.business.dto.ProjectCompleteTimesDTO;
import com.jsyl.lwbk.business.service.PrepareClassService;
import com.jsyl.lwbk.common.core.controller.BaseController;
import com.jsyl.lwbk.common.core.domain.AjaxResult;
import com.jsyl.lwbk.common.core.page.TableDataInfo;
import com.jsyl.lwbk.framework.util.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 训练计划
 */
@Controller
@RequestMapping("/business/prepareClass")
public class PrepareClassController extends BaseController {

    private String prefix = "business/prepareClass";

    @Autowired
    PrepareClassService prepareClassService;

    /**
     * 页面跳转-备课主页列表
     * @param mmap
     * @return
     */
    @GetMapping()
    public String child(ModelMap mmap) {
        mmap.put("teacherId", ShiroUtils.getUserId());
        return prefix + "/prepareClassList";
    }
    /**
     * 页面跳转-备课
     * @param mmap
     * @return
     */
    @GetMapping("/prepareClass/{id}/{ageGrade}")
    public String prepareClass(@PathVariable("id")Long id,@PathVariable("ageGrade")Integer ageGrade, ModelMap mmap) {
        mmap.put("childCourseId", id);
        mmap.put("ageGrade", ageGrade);
        return prefix + "/prepareClass";
    }
    /**
     * 页面跳转-选择训练包
     * @param mmap
     * @return
     */
    @GetMapping("/checkTrainPackage/{childCourseId}")
    public String checkTrainPackage(@PathVariable("childCourseId")Long childCourseId, ModelMap mmap) {
        mmap.put("childCourseId", childCourseId);
        return prefix + "/checkTrainPackage";
    }
    /**
     * 页面跳转-选择训练主题
     * @param mmap
     * @return
     */
    @GetMapping("/checkTrainTheme/{childCourseId}")
    public String checkTrainTheme(@PathVariable("childCourseId")Long childCourseId, ModelMap mmap) {
        mmap.put("childCourseId", childCourseId);
        return prefix + "/checkTrainTheme";
    }
    /**
     * 页面跳转-替换环节项目
     * @param mmap
     * @return
     */
    @GetMapping("/replaceInitLink/{childCourseId}/{ageGrade}")
    public String replaceInitLink(@PathVariable("childCourseId")Long childCourseId,
                                  @PathVariable("ageGrade")Integer ageGrade,ModelMap mmap) {
        mmap.put("childCourseId", childCourseId);
        mmap.put("ageGrade", ageGrade);
        return prefix + "/replaceInitLink";
    }
    /**
     * 页面跳转-替换偏难项目
     * @param mmap
     * @return
     */
    @GetMapping("/replaceDifficulty/{childProjectId}/{childId}/{age}/{linkNo}")
    public String replaceDifficulty(@PathVariable("childProjectId")Long childProjectId,
                                    @PathVariable("childId")Long childId,
                                  @PathVariable("age")Integer age,
                                    @PathVariable("linkNo")Integer linkNo,
                                    ModelMap mmap) {
        mmap.put("childProjectId", childProjectId);
        mmap.put("childId", childId);
        mmap.put("age", age);
        mmap.put("linkNo", linkNo);
        return prefix + "/replaceDifficulty";
    }
    /**
     * 页面跳转-查看基础表现
     * @param childCourseId
     * @param childId
     * @param mmap
     * @return
     */
    @GetMapping("/viewBasicExpression/{childCourseId}/{childId}")
    public String editBasicExpression(@PathVariable("childCourseId") String childCourseId,
                                      @PathVariable("childId")Long childId, ModelMap mmap) {
        mmap.put("childCourseId", childCourseId);
        mmap.put("childId", childId);
        return prefix + "/viewBasicExpression";
    }
    /**
     * 页面跳转-学员信息
     * @param childCourseId
     * @param mmap
     * @return
     */
    @GetMapping("/childInfo/{childCourseId}")
    public String editBasicExpression(@PathVariable("childCourseId") String childCourseId,ModelMap mmap) {
        mmap.put("childCourseId", childCourseId);
        return prefix + "/childInfo";
    }

    /**
     *备课主页分页数据
     *
     * @return
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo findList(ChildCourseDTO dto) {
        startPage();
        List<ChildCourse> list = prepareClassService.list(dto,ShiroUtils.getSysUser());
        return getDataTable(list);
    }

    /**
     *备课学生分页数据
     *
     * @return
     */
    @PostMapping("/childList")
    @ResponseBody
    public TableDataInfo childList(ChildCourseDTO dto) {

        //生成本节课项目
        this.prepareClassService.initProject(dto.getChildCourseId(),ShiroUtils.getLoginName());
        startPage();
        List<CourseChildProject> list = prepareClassService.childList(dto.getChildCourseId(),ShiroUtils.getLoginName());
        return getDataTable(list);
    }
    /**
     *学员信息
     *
     * @return
     */
    @PostMapping("/childInfo")
    @ResponseBody
    public TableDataInfo childInfo(ChildCourseDTO dto) {
        startPage();
        List<ChildInfoDTO> list = prepareClassService.childInfo(dto.getChildCourseId());
        return getDataTable(list);
    }

    /**
     * 判断是否能备课
     * @return
     */
    @GetMapping("/checkPrepare/{childCourseId}")
    @ResponseBody
    public AjaxResult checkPrepare(@PathVariable("childCourseId")Long childCourseId) {
        return success(this.prepareClassService.checkPrepare(childCourseId));
    }
    /**
     * 打印题目纸
     * @return
     */
    @GetMapping("/printScoreRecord/{childCourseId}")
    @ResponseBody
    public AjaxResult printScoreRecord(@PathVariable("childCourseId")Long childCourseId) {
        return success(this.prepareClassService.printScoreRecord(childCourseId));
    }
    /**
     * 判断是否能取消备课
     * @return
     */
    @GetMapping("/checkCancelPrepare/{childCourseId}")
    @ResponseBody
    public AjaxResult checkCancelPrepare(@PathVariable("childCourseId")Long childCourseId) {
        return success(this.prepareClassService.checkCancelPrepare(childCourseId));
    }

    /**
     * 判断是否能取消备课
     * @return
     */
    @GetMapping("/checkEnterScore/{childCourseId}")
    @ResponseBody
    public AjaxResult checkEnterScore(@PathVariable("childCourseId")Long childCourseId) {
        return success(this.prepareClassService.checkEnterScore(childCourseId));
    }
    /**
     * 判断是否需要选择训练包
     * @return
     */
    @GetMapping("/hasCheckTrainPackage/{childCourseId}")
    @ResponseBody
    public AjaxResult hasCheckTrainPackage(@PathVariable("childCourseId")Long childCourseId) {
        return success(this.prepareClassService.hasCheckTrainPackage(childCourseId));
    }
    /**
     * 判断是否需要选择训练主题
     * @return
     */
    @GetMapping("/hasCheckTrainTheme/{childCourseId}")
    @ResponseBody
    public AjaxResult hasCheckTrainTheme(@PathVariable("childCourseId")Long childCourseId) {
        return success(this.prepareClassService.hasCheckTrainTheme(childCourseId));
    }



    /**
     * 训练包选择下拉框数据
     * @return
     */
    @GetMapping("/getCheckTrainPackage/{childCourseId}")
    @ResponseBody
    public AjaxResult getCheckTrainPackage(@PathVariable("childCourseId")Long childCourseId) {
        return success(this.prepareClassService.checkTrainPackage(childCourseId,ShiroUtils.getLoginName()));
    }
    /**
     * 训练主题选择下拉框数据
     * @return
     */
    @GetMapping("/getCheckTrainTheme/{childCourseId}")
    @ResponseBody
    public AjaxResult getCheckTrainTheme(@PathVariable("childCourseId")Long childCourseId) {
        return success(this.prepareClassService.getCheckTrainTheme(childCourseId,ShiroUtils.getLoginName()));
    }

    /**
     *保存备课选择的训练包
     *
     * @return
     */
    @PostMapping("/saveTrainPackage")
    @ResponseBody
    public AjaxResult saveTrainPackage(@RequestBody ChildCourseDTO dto) {
        this.prepareClassService.saveTrainPackage(dto,ShiroUtils.getLoginName());
        return success();
    }
    /**
     *保存备课集训班选择的主题
     *
     * @return
     */
    @PostMapping("/saveTrainTheme")
    @ResponseBody
    public AjaxResult saveTrainTheme(@RequestBody ChildCourseDTO dto) {
        this.prepareClassService.saveTrainTheme(dto,ShiroUtils.getLoginName());
        return success();
    }

    /**
     *完成备课
     *
     * @return
     */
    @PostMapping("/completePrepare")
    @ResponseBody
    public AjaxResult completePrepare(@RequestParam("childCourseId") Long childCourseId) {
        this.prepareClassService.completePrepare(childCourseId);
        return success();
    }

    /**
     * 判断是否能未上课
     * @return
     */
    @GetMapping("/checkNotClass/{childCourseId}")
    @ResponseBody
    public AjaxResult checkNotClass(@PathVariable("childCourseId")Long childCourseId) {
        return success(this.prepareClassService.checkNotClass(childCourseId));
    }
    /**
     *未上课
     *
     * @return
     */
    @PostMapping("/notClass")
    @ResponseBody
    public AjaxResult notClass(@RequestParam("childCourseId") Long childCourseId) {
        this.prepareClassService.notClass(childCourseId);
        return success();
    }
    /**
     *取消备课
     *
     * @return
     */
    @PostMapping("/cancelPrepare")
    @ResponseBody
    public AjaxResult cancelPrepare(@RequestParam("childCourseId") Long childCourseId) {
        this.prepareClassService.cancelPrepare(childCourseId);
        return success();
    }

    /**
     *取消备课
     *
     * @return
     */
    @PostMapping("/listCourseChild")
    @ResponseBody
    public AjaxResult listCourseChild(@RequestParam("childCourseId") Long childCourseId) {
        return success(this.prepareClassService.listCourseChild(childCourseId));
    }

    /**
     *保存替换项目
     *
     * @return
     */
    @PostMapping("/replaceInitLink")
    @ResponseBody
    public AjaxResult replaceInitLink(@RequestBody CourseChildProject dto) {
        this.prepareClassService.replaceInitLink(dto);
        return success();
    }
    /**
     *保存偏难项目替换
     *
     * @return
     */
    @PostMapping("/replaceDifficulty")
    @ResponseBody
    public AjaxResult replaceDifficulty(@RequestBody CourseChildProject dto) {
        this.prepareClassService.replaceDifficulty(dto);
        return success();
    }

    /**
     *保存项目训练量
     *
     * @return
     */
    @PostMapping("/getProjectCompleteTimes")
    @ResponseBody
    public AjaxResult getProjectCompleteTimes(@RequestBody ProjectCompleteTimesDTO dto) {
        return success(prepareClassService.getProjectCompleteTimes(dto.getChildId(),dto.getProjectCodes()));
    }

}
